<?php
include("../../settings/database.php");

class register extends database
{
        public  $username;
        public  $password;
        public  $retype;
        public  $fname;
        public  $mname;
        public  $lname;
        public  $gender;
        public  $bdate;
        public  $contact;
        public  $email;
        public  $house;
        public  $brgy;
        public  $town;
        public  $prov;
        public  $batch;
        
        public function register_alumni()
        {
                if($this->username==null)
                {
                        return "
                                        <div class='error'>Please enter your username!</div>
                                        <script type='text/javascript'>
                                            window.location.hash=' ';
                                        </script>
                                "; 
                }
                elseif($this->password==$this->username)
                {
                        return "
                                        <div class='error'>Password must not be like username!</div>
                                        <script type='text/javascript'>
                                            window.location.hash=' ';
                                        </script>
                                ";
                }
                elseif($this->password==null)
                {
                        return "
                                        <div class='error'>Please enter your password!</div>
                                        <script type='text/javascript'>
                                            window.location.hash=' ';
                                        </script>
                                ";
                }
                elseif($this->retype==null)
                {
                        return "
                                        <div class='error'>Please retype your password!</div>
                                        <script type='text/javascript'>
                                            window.location.hash=' ';
                                        </script>
                                ";
                }
                elseif($this->retype!=$this->password)
                {
                        return "
                                        <div class='error'>Password did not match!</div>
                                        <script type='text/javascript'>
                                            window.location.hash=' ';
                                        </script>
                                ";
                }
                elseif($this->fname==null)
                {
                        return "
                                        <div class='error'>Please enter your first name!</div>
                                        <script type='text/javascript'>
                                            window.location.hash=' ';
                                        </script
                                ";
                }
                elseif($this->mname==null)
                {
                        return "
                                        <div class='error'>Please enter your middle name!</div>
                                        <script type='text/javascript'>
                                            window.location.hash=' ';
                                        </script
                                ";
                }
                elseif($this->lname==null)
                {
                        return "
                                        <div class='error'>Please enter your last name!</div>
                                        <script type='text/javascript'>
                                            window.location.hash=' ';
                                        </script
                                ";
                }
                elseif($this->gender=='default')
                {
                        return "
                                        <div class='error'>Please select your gender!</div>
                                        <script type='text/javascript'>
                                            window.location.hash=' ';
                                        </script
                                ";
                }
                elseif($this->bdate==null)
                {
                        return "
                                        <div class='error'>Please enter your birthdate!</div>
                                        <script type='text/javascript'>
                                            window.location.hash=' ';
                                        </script
                                ";
                }
                elseif($this->contact==null)
                {
                        return "
                                        <div class='error'>Please enter your contact number!</div>
                                        <script type='text/javascript'>
                                            window.location.hash=' ';
                                        </script
                                ";
                }
                elseif(!is_numeric($this->contact))
                {
                        return "
                                        <div class='error'>Contact number must be numeric!</div>
                                        <script type='text/javascript'>
                                            window.location.hash=' ';
                                        </script
                                ";
                }
                elseif(strlen($this->contact)!=11)
                {
                        return "
                                        <div class='error'>Contact number must be 11 digits!</div>
                                        <script type='text/javascript'>
                                            window.location.hash=' ';
                                        </script
                                ";
                }
                elseif($this->email==null)
                {
                        return "
                                        <div class='error'>Please enter your email address!</div>
                                        <script type='text/javascript'>
                                            window.location.hash=' ';
                                        </script
                                ";
                }
                elseif(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $this->email) && $this->email != null)
                {
                        return "
                                        <div class='error'>Invalid email address!</div>
                                        <script type='text/javascript'>
                                            window.location.hash=' ';
                                        </script
                                ";
                }
                elseif($this->house==null)
                {
                        return "
                                        <div class='error'>Please enter your house/street number!</div>
                                        <script type='text/javascript'>
                                            window.location.hash=' ';
                                        </script
                                ";
                }
                elseif(!is_numeric($this->house))
                {
                        return "
                                        <div class='error'>House/street number must be numeric!</div>
                                        <script type='text/javascript'>
                                            window.location.hash=' ';
                                        </script
                                ";
                }
                elseif($this->brgy==null)
                {
                        return "
                                        <div class='error'>Please enter your barangay address!</div>
                                        <script type='text/javascript'>
                                            window.location.hash=' ';
                                        </script
                                ";
                }
                elseif($this->town==null)
                {
                        return "
                                        <div class='error'>Please enter your city/town address!</div>
                                        <script type='text/javascript'>
                                            window.location.hash=' ';
                                        </script
                                ";
                }
                elseif($this->prov==null)
                {
                        return "
                                        <div class='error'>Please enter your province!</div>
                                        <script type='text/javascript'>
                                            window.location.hash=' ';
                                        </script
                                ";
                }
                elseif($this->batch=='default')
                {
                        return "
                                        <div class='error'>Please select your batch year!</div>
                                        <script type='text/javascript'>
                                            window.location.hash=' ';
                                        </script
                                ";
                }
                else
                {
                        $insert1 = $this->query("
                                                    INSERT INTO tbl_reg_alumni
                                                         (
                                                             ALUM_USER_NAME,
                                                             ALUM_PASSWORD,
                                                             ALUM_FIRST_NAME,
                                                             ALUM_MIDDLE_NAME,
                                                             ALUM_LAST_NAME,
                                                             ALUM_GENDER,
                                                             ALUM_BIRTHDAY,
                                                             ALUM_CONTACT_NUM,
                                                             ALUM_EMAIL_ADD,
                                                             ALUM_HOUSE_NUM,
                                                             ALUM_BARANGAY,
                                                             ALUM_TOWN,
                                                             ALUM_PROVINCE,
                                                             ALUM_ISACTIVE
                                                         )
                                                     VALUES
                                                         (
                                                             '".$this->username."',
                                                             '".sha1($this->password)."',
                                                             '".$this->fname."',
                                                             '".$this->mname."',
                                                             '".$this->lname."',
                                                             '".$this->gender."',
                                                             '".$this->bdate."',
                                                             '".$this->contact."',
                                                             '".$this->email."',
                                                             '".$this->house."',
                                                             '".$this->brgy."',
                                                             '".$this->town."',
                                                             '".$this->prov."',
                                                             'true'
                                                         )
                                                ");
                        
                        $insert2 = $this->query("
                                                    INSERT INTO tbl_batch_reg
                                                        (
                                                            BATCH_REG_YEAR,
                                                            BATCH_REG_ALUM_USERNAME
                                                        )
                                                    VALUES
                                                        (
                                                            '".$this->batch."',
                                                            '".$this->username."'
                                                        )
                                                ");
                        
                        if($insert1 & $insert2)
                        {
                                return "
                                                <div class='success'>Registration Saved!</div>
                                                <script type='text/javascript'>
                                                    window.location.hash=' ';
                                                </script
                                        ";
                        }
                        else
                        {
                                return "
                                                <div class='error'>Registration Failed!</div>
                                                <script type='text/javascript'>
                                                    window.location.hash=' ';
                                                </script
                                        ";
                        }
                }
        }
}

?>